﻿@{
    Layout = "~/Views/Shared/_LayoutForEUI.cshtml";
    var listType = ViewBag.listType as List<SGArchiveSystem7x.Models.CComboboxModel>;
    var borrow = ViewBag.borrow as List<SGArchiveSystem7x.Models.CColumnsModel>;
  }
        <table id="LogBorrow_Index_grid" class="easyui-datagrid" style="width:100%;" title="借阅日志" data-options="
       rownumbers:true,
       singleSelect:true,
       autoRowHeight:false,
       pagination:true,
       fitColumns:true,
       fit:true,
       striped:true,
       checkOnSelect:false,
       selectOnCheck:false,
       toolbar:'#LogBorrow_Index_tb',
       collapsible:false,
       pageSize: @SGArchiveSystem7x.Models.CCommonsModels.PageSize,
       pageList:[10,15,20]">

            <thead frozen="true">
                <tr>
                    @{
                        foreach (var c in borrow)
                        {
                            if (c.Frozen)
                            {
                                 <th field="@c.FieldValue" width="@c.Len" align="center" formatter="@c.Formate">@c.FieldText</th>

                            }
                        }
                    }
                </tr>
            </thead>
            <thead>
                <tr>
                    @{
                        foreach (var c in borrow)
                        {
                            if (!c.Frozen)
                            {
                                    <th field="@c.FieldValue" width="@c.Len" align="center" formatter="@c.Formate">@c.FieldText</th>
                            }

                        }
                    }
                </tr>
            </thead>
        </table>

        <div id="LogBorrow_Index_tb" style="padding:2px 5px;">
            <input type="text" class="easyui-textbox" label="姓名:" labelwidth="50px" labelalign="right" style="width:180px" id="LogBorrow_Index_txtuname" />
            <input type="text" class="easyui-textbox" label="档号:" labelwidth="40px" labelalign="right" style="width:180px" id="LogBorrow_Index_txtDH" />
            <input type="text" class="easyui-textbox" label="题名:" labelwidth="40px" labelalign="right" style="width:180px" id="LogBorrow_Index_txtTM" />
            <select class="easyui-combobox" label="档案类型:" labelwidth="60px" labelalign="right" style="width:180px" id="LogBorrow_Index_cmbType" editable="false" panelHeight="auto">
                @{
                foreach (var c in listType){
                <option value="@c.ID">@c.Text</option>
                }
                }
            </select>
            <input type="text" class="easyui-datebox" data-options="editable:false" label="起始时间:" labelalign="right" labelwidth="60px" style="width:180px" id="LogBorrow_Index_txtSTime" />
            <input type="text" class="easyui-datebox" data-options="editable:false" label="结束时间:" labelalign="right" labelwidth="60px" style="width:180px" id="LogBorrow_Index_txtETime" />
            <a href="javascript:void(0);" id="LogBorrow_Index_btnQuery" class="easyui-linkbutton button-blue" iconCls="icon-search" onclick="Search()" style="width:110px;height:30px;">查询</a>
            
        </div>

        <script>
            $(document).ready(function ()  {
                $('#LogBorrow_Index_grid').datagrid({
                    url: '/LogBorrow/Get_ajaxLogBorrowList?uname&dh&tm&type=-1&stime&etime',
                    singleSelect: true,
                    method: 'post',
                    onLoadSuccess: function (data) {
                        $('.pagination-page-list').hide();
                    }
                });
                InitPagenation();
            })

            //查询
            function Search() {
                var uname = $('#LogBorrow_Index_txtuname').val();
                var dh = $('#LogBorrow_Index_txtDH').val();
                var tm = $('#LogBorrow_Index_txtTM').val();
                var type = $('#LogBorrow_Index_cmbType').combobox('getValue');
                var stime = $('#LogBorrow_Index_txtSTime').datebox('getValue');
                var etime = $('#LogBorrow_Index_txtETime').datebox('getValue');
                $('#LogBorrow_Index_grid').datagrid('options').url = '/LogBorrow/Get_ajaxLogBorrowListSearch?uname=' + uname + '&dh=' + dh + '&tm=' + tm + '&type=' + type + '&stime=' + stime + '&etime=' + etime
                $('#LogBorrow_Index_grid').datagrid('load');
                $('#LogBorrow_Index_grid').datagrid('options').pageNumber = 1;
            }

            ///初始化分页
            function InitPagenation() {
                //设置分页控件
                var p = $('#LogBorrow_Index_grid').datagrid('getPager');
                $(p).pagination({
                    onSelectPage: function (pageNumber, pageSize) {
                        SearchPager(pageNumber, pageSize);
                    }
                })

            function SearchPager(num, size) {

                $('#LogBorrow_Index_grid').datagrid('options').url = '/LogBorrow/Get_ajaxLogBorrowListPage?num=' + num +
                    '&size=' + size;
                $('#LogBorrow_Index_grid').datagrid('reload');
                $('#LogBorrow_Index_grid').datagrid('options').pageNumber = num;
                $('#LogBorrow_Index_grid').datagrid('options').pageSize = size;
            }

            //导出xls
            function Download() {
                var uname = $('#LogBorrow_Index_txtuname').val();
                var dh = $('#LogBorrow_Index_txtDH').val();
                var tm = $('#LogBorrow_Index_txtTM').val();
                var type = $('#LogBorrow_Index_cmbType').combobox('getValue');
                var stime = $('#LogBorrow_Index_txtSTime').datebox('getValue');
                var etime = $('#LogBorrow_Index_txtETime').datebox('getValue');
                var grid = $('#LogBorrow_Index_grid');
                var options = grid.datagrid('getPager').data("pagination").options;
                var total = options.total;
                if (total > 100) {
                    if (window.confirm('数据量过多，是否仍然需要导出？')) {
                        $.ajax({
                            url: '/LogBorrow/DownLoadxls?uname=' + uname + '&dh=' + dh + '&tm=' + tm + '&type=' + type + '&stime=' + stime + '&etime=' + etime,
                            dataType: "text",
                            type: "post",
                            success: function (data) {
                                window.open(data);
                            }
                        });
                    }
                }
                else {
                    $.ajax({
                        url: '/LogBorrow/DownLoadxls?uname=' + uname + '&dh=' + dh + '&tm=' + tm + '&type=' + type + '&stime=' + stime + '&etime=' + etime,
                        dataType: "text",
                        type: "post",
                        success: function (data) {
                            //alert('下载');
                            window.open(data);
                        }
                    });
                }
            }
        </script>
